﻿/**
*叠加CAD/SHP数据类
*@module modules.analysis
*@class DCI.AddCad
*@constructor initialize
*@extends Class
*/
define("analysis/addcad", [
    "leaflet",
    "core/dcins",
    "analysis/colorpick"
], function (L) {
    L.DCI.AddCad = L.Class.extend({
        /**
        *类ID
        *@property id
        *@type {String}
        */
        id: 'AddCad',
        /**
        *SWFUpload实例对象
        *@property swfu
        *@type {Object}
        */
        swfu: null,
        /**
        *初始化
        *@method initialize
        */
        initialize: function(config) {
            this.initArray();
            //linghuam add  说明： config{title:'窗口标题文字',selectInfo:'选择按钮前面的说明文字',lineStyle:'默认线型',color:'默认颜色'}  如: var config = { title: '建设项目合规性检查', selectInfo: '项目导入：',linestyle:3,color:'#ff0000' };
            this.config = $.extend({ lineStyle: 1, color: '#000000' }, config);  
            swfu = null;
        },
        /**
        *置空
        *@method _addContextmenu
        *@private
        */
        initArray: function() {
            this.cadUrlArray = [];
            this.cadFileNameArray = [];
            this.shpNameArray = [];
            this.shpUrlArray = [];
        },
        /**
        *初始化叠加窗体HTML
        *@method initModal
        *@param type {String} ("cad")("shp")
        *@public
        */
        initModal: function(type) {
            var html =' <div id="frmMain" action="" runat="server" enctype="multipart/form-data">'
                + ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
                +(this.config.selectInfo || '请选择要叠加的文件：')
                + '<span id="spanButtonPlaceHolder"></span>'
                + '<div id="divprogresscontainer" class="divprogress"></div>'
                + '<div id="divprogressGroup" style="display:none;"></div>'
                + '</div>';
            if (type != "cad") {
                html += ' <div class="op1">'
                    + '<p style="font-size:14px;float:left;font-weight: bold;margin-left: 10px;margin-top: 5px;">图形设置:</p>'
                    + '<p style="font-size:12px; position:absolute;top:50px; left:20px;">线型：</p>'
                    + '<div class="op" >'
                    + '<div id="jieguo" ><p id="num">' + this.config.lineStyle + '</p><hr id="line" style="border-top: ' + this.config.lineStyle + 'px solid #000;margin-top: 15px; margin-bottom: 5px; width:80px;"/></div>'
                    + '<div class="linetogg"><span class="icon-triangle"></span></div>'
                    + '<ul id="cuxi" class="op-list hide">'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">1</p><hr  style="border-top: 1px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">2</p><hr  style="border-top: 2px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">3</p><hr style="border-top: 3px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">4</p><hr style="border-top: 4px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">5</p><hr style="border-top: 5px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">6</p><hr style="border-top: 6px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '<li class="op-list-item"><p style="width:15px;float: left;">7</p><hr style="border-top: 7px solid #000;margin-top: 5px; margin-bottom: 5px; width:90px;"/></li>'
                    + '</ul>'
                    + '</div>'
                    + '<p style="font-size:12px; position:absolute;top:50px; left:230px;">颜色：</p>'
                    + '<div id="custom" class="input_cxcolor" readonly value="'+this.config.color+'" ><div style="background-color:#ffffff;width=50px;height:28px" ><span class="icon-Paint-bucket" style="color: #787878;font-size: 16px;top: 5px;left: 8px;position: absolute;">'
                    + '</span><span style="font-size: 16px;position: absolute;right: 2px;top: 5px;color: #787878;" class="icon-triangle"><span></div></div>'
                    + '<div id="yanse" style="background:'+this.config.color+'"></div>'
                    + '</div>';
            }
            html += '<p class="zhuji">*请上传数据后再点击确定添加图层</p>'
                + '<input id="queding"  type="button" value="确  定"/>';
            return html;
        },
        /**
        *弹出添加对话框
        *@method addmodal
        *@param container {String} 容器ID
        */
        addmodal: function(type, container) {
            //构建叠加控件
            var html = this.initModal(type);
            //判断是否有传入容器
            if (container != null && container != "" ) {
                $("#" + container).html(html);
            } else {
                //如果没有传入容器则创建窗体
                container = "djcad";
                if ($("#" + container).length == 0) {
                    //初始化弹出窗体标题栏及关闭按钮
                    $(".out-container").append('<div id="' + container + '" style="height:' + (type == "cad" ? "350px" : "450px") + '" class="ui-widget-content"></div>');
                } else {
                    document.getElementById(container).innerHTML = "";
                }
                $("#" + container).html('<div id="dj_title" class="dj_title"><p id="scnum"></p><p id="scnum1"></p></div><span id="close" class="icon-close2"></span>' + html);

                $("#close").bind('click', L.bind(function() {
                    this.initArray();
                    var obj = document.getElementById(container); //解决浏览器兼容问题
                    obj.parentNode.removeChild(obj);
                }, this));
                L.dci.app.util._drag(container, "dj_title");
            }
            this.containerId = container;
            $(".op").bind('click', function() {
                var op_list = this.children[2];
                if (op_list.className.indexOf('hide') > -1) {
                    op_list.className = op_list.className.replace(/(^|\s)hide(\s|$)/, '');
                } else {
                    op_list.className += ' hide';
                }
            });
            $(".op-list-item").bind('click', function() {
                var a = $(this).index() + 1;
                $("#num").html(a);
                $("#line").css("border-top-width", a + "px");
            });
            $("#scnum1").css("left", $("#scnum").css("width"));
            $("#custom").cxColor();
            $("#custom").bind('change', function() {
                $("#yanse").css("background", this.value);
                $("#custom").attr("value", this.value);
            });

            $('#' + container).css("display", "block");
            $(".op1").css("display", "block");
        },
        /**
        *配置上传参数
        *@method _GetUploadObj
        *@param type {String} ("cad")("shp")
        *@param container {String} 容器ID
        *@private
        */
        _GetUploadObj: function(type,container) {
            this.addmodal(type, container);
            this._show(type);
            var fileTypes, uploadUrl;
            var url = Project_ParamConfig.cadserver; //叠加SHP服务器地址
            var file_upload_limit = 3;
            var uploadSuccess = null;
            if (type == "cad") {
                fileTypes = "*.dwg";
                uploadUrl = url + "/Request/SaveCADFile.ashx";
                file_upload_limit = 3;
                uploadSuccess = this.uploadCADSuccess;
            } else {
                //fileTypes = "*.shp;*.dbf;*.shx";       //;*.prj;*.sbn;*.sbx";
                fileTypes = "*.shp;";
                uploadUrl = url + "/Request/SaveSHPFile.ashx";
                file_upload_limit = 5;
                uploadSuccess = this.uploadSHPSuccess;
            }
            if (url == null) return null;
            var flashUrl = url + "/SwfUpload/swfupload/swfupload.swf";
            var settings = {
                flash_url: flashUrl,
                upload_url: uploadUrl,
                file_size_limit: "200MB",
                file_types: fileTypes,
                file_types_description: "All Files",
                file_upload_limit: file_upload_limit,
                file_queue_limit: 0,
                custom_settings: {
                    progressTarget: "divprogresscontainer",
                    progressGroupTarget: "divprogressGroup",
                    container_css: "progressobj",
                    icoNormal_css: "icon-CADicon",
                    _this: this,
                    icoWaiting_css: "IcoWaiting",
                    icoUpload_css: "IcoUpload",
                    fname_css: "fle ftt",
                    state_div_css: "statebarSmallDiv",
                    state_bar_css: "statebar",
                    percent_css: "ftt fper",
                    href_delete_css: "ftt icon-close1 fd1",
                    href_delete_cssl: "ftt icon-pitch-on fd2",
                    s_cnt_progress: "cnt_progress",
                    s_cnt_span_text: "fle",
                    s_cnt_progress_statebar: "cnt_progress_statebar",
                    s_cnt_progress_percent: "cnt_progress_percent",
                    s_cnt_progress_uploaded: "cnt_progress_uploaded",
                    s_cnt_progress_size: "cnt_progress_size"
                },
                debug: false,
                button_width: "65",
                button_height: "30",
                button_placeholder_id: "spanButtonPlaceHolder",
                button_text: '<span class="theFont">选择...</span>',
                button_text_style: ".theFont{ font-size: 12px;color:#0068B7;text-decoration:underline;}",
                button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                button_cursor: SWFUpload.CURSOR.HAND,
                button_text_left_padding: 8,
                button_text_top_padding: 13,
                file_queued_handler: fileQueued,
                file_queue_error_handler: this._fileQueueError,
                upload_start_handler: uploadStart,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: uploadSuccess,
                upload_complete_handler: uploadComplete,
                file_dialog_complete_handler: fileDialogComplete
            };
            swfu = new SWFUpload(settings);
        },
        _GetUploadObj2: function (type, container) {  //可一个按钮叠加shp或cad
            this.addmodal(type, container);
            this._show(type);
            var fileTypes, uploadUrl;
            var url = Project_ParamConfig.cadserver; //叠加SHP服务器地址
            var file_upload_limit = 3;
            var uploadSuccess = null;
            if (type == "cad") {
                fileTypes = "*.dwg";
                uploadUrl = url + "/Request/SaveCADFile.ashx";
                file_upload_limit = 3;
                uploadSuccess = this.uploadCADSuccess;
            } else {
                fileTypes = "*.shp;*.dwg";
                uploadUrl ="";
                file_upload_limit = 3;
                uploadSuccess = this.uploadSHPSuccess2;
            }
            if (url == null) return null;
            var flashUrl = url + "/SwfUpload/swfupload/swfupload.swf";
            var settings = {
                flash_url: flashUrl,
                upload_url: uploadUrl,
                file_size_limit: "200MB",
                file_types: fileTypes,
                file_types_description: "All Files",
                file_upload_limit: file_upload_limit,
                file_queue_limit: 0,
                custom_settings: {
                    progressTarget: "divprogresscontainer",
                    progressGroupTarget: "divprogressGroup",
                    container_css: "progressobj",
                    icoNormal_css: "icon-CADicon",
                    _this: this,
                    icoWaiting_css: "IcoWaiting",
                    icoUpload_css: "IcoUpload",
                    fname_css: "fle ftt",
                    state_div_css: "statebarSmallDiv",
                    state_bar_css: "statebar",
                    percent_css: "ftt fper",
                    href_delete_css: "ftt icon-close1 fd1",
                    href_delete_cssl: "ftt icon-pitch-on fd2",
                    s_cnt_progress: "cnt_progress",
                    s_cnt_span_text: "fle",
                    s_cnt_progress_statebar: "cnt_progress_statebar",
                    s_cnt_progress_percent: "cnt_progress_percent",
                    s_cnt_progress_uploaded: "cnt_progress_uploaded",
                    s_cnt_progress_size: "cnt_progress_size"
                },
                debug: false,
                button_width: "65",
                button_height: "30",
                button_placeholder_id: "spanButtonPlaceHolder",
                button_text: '<span class="theFont">选择...</span>',
                button_text_style: ".theFont{ font-size: 12px;color:#0068B7;text-decoration:underline;}",
                button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
                button_cursor: SWFUpload.CURSOR.HAND,
                button_text_left_padding: 8,
                button_text_top_padding: 13,
                file_queued_handler: fileQueued,
                file_queue_error_handler: this._fileQueueError,
                upload_start_handler: this.uploadStart,
                upload_progress_handler: uploadProgress,
                upload_error_handler: uploadError,
                upload_success_handler: uploadSuccess,
                upload_complete_handler: uploadComplete,
                file_dialog_complete_handler: fileDialogComplete
            };
            swfu = new SWFUpload(settings);
        },
        uploadStart: function (file) {
            try {
                //判断shp，cad
                var url = Project_ParamConfig.cadserver;
                var ShpUploadUrl = url + "/Request/SaveSHPFile.ashx";
                var CadUploadUrl = url + "/Request/SaveCADFile.ashx";
                if (file.type.toLowerCase() == ".shp") swfu.setUploadURL(ShpUploadUrl);
                if (file.type.toLowerCase() == ".dwg") swfu.setUploadURL(CadUploadUrl);

                var progress = new FileProgress(file, swfu.settings.custom_settings.progressTarget);
                progress.setUploadState(3, this.settings);
            }
            catch (ex) { }
            return true;
        },

        /**
        *叠加SHP文件
        *@method addshp
        *container 容器id 如果不为空则填充到该容器
        *fn 回调
        *cx 上下文环境
        */
        addshp: function(container,fn, cx) {
            this._GetUploadObj("shp", container);
            //确定事件
            $("#queding").off();
            $("#queding").bind('click', L.bind(function() {
                var url = this.shpUrlArray.join(';');
                if (url == null || !url) {
                    $('.zhuji').css('display', 'block');
                    return;
                }
                L.dci.app.util.showLoading();
                var tUrl = Project_ParamConfig.cadserver + "/Request/RequestServices.ashx";
                var params = {
                    shapePath: url,
                    type: "shape"
                };
                var color = $("#custom").attr("value");
                var numb = $("#num").html();
                $.extend(params, {
                    lineWidth: numb,
                    lineColor: color
                });
                this.addshp1(params, tUrl, fn, cx);
                this._hide();
            }, this));
        },

        //只返回要素
        addshp_3: function (fn, cx) {
            this._GetUploadObj("shp");
            //确定事件
            $("#queding").off();
            $("#djcad").find(".op1").hide();
            $("#queding").bind('click', L.bind(function () {
                var url = this.shpUrlArray.join(';');
                if (url == null || !url) {
                    $('.zhuji').css('display', 'block');
                    return;
                }
                L.dci.app.util.showLoading();
                var tUrl = Project_ParamConfig.cadserver + "/Request/RequestServices.ashx";
                var params = {
                    shapePath: url,
                    type: "shape"
                };
                var color = $("#custom").attr("value");
                var numb = $("#num").html();
                $.extend(params, {
                    lineWidth: numb,
                    lineColor: color
                });
                this.addshp_2(params, tUrl, fn, cx);
                this._hide();
            }, this));
        },

        //同一个"选择..."按钮，既能选择shp文件，又能选择cad文件。不添加到地图，只返回要素。并拥有自定义窗体。
        addshp_4: function (container,fn, cx) {
            this._GetUploadObj2("shp", container);
            //确定事件
            $("#queding").off();
            $("#queding").bind('click', L.bind(function () {
                var url = this.shpUrlArray.join(';') || this.cadUrlArray.join(";");
                if (url == null || !url) {
                    $('.zhuji').css('display', 'block');
                    return;
                }
                L.dci.app.util.showLoading();
                var tUrl = Project_ParamConfig.cadserver + "/Request/RequestServices.ashx";
                //shp和cad处理
                var ind = url.lastIndexOf(".", url.length - 1);
                var type = url.slice(ind).toLowerCase();
                if (type == ".shp") {
                    var params = {
                        shapePath: url,
                        type: "shape"
                    };
                    var color = $("#custom").attr("value");
                    var numb = $("#num").html();
                    $.extend(params, {
                        lineWidth: numb,
                        lineColor: color
                    });
                    this.addshp_2(params, tUrl, fn, cx);
                } else {
                    var layertypes = "Polyline;Annotation";
                    var color = $("#custom").attr("value");
                    var numb = $("#num").html();
                    var params = {
                        "type": "cad",
                        "dwg": url,
                        "layerTypes": layertypes,
                        "lineWidth": numb,
                        "lineColor": color
                    };
                    this.addcad_2(params, tUrl, fn, cx);
                }
                this._hide();
            }, this));
        },

        /**
        *弹出框配置（“叠加CAD”或“叠加SHP”）
        *@method _show
        *@param type {String} ("cad")("shp")
        *@private
        */
        _show: function(type) {
            var hm = $("#divprogresscontainer");
            hm.html("");
            hm.removeClass('divprogress1');
            hm.addClass("divprogress");
            $(".zhuji").css("display", "none");
            if (type == "cad")
                $("#scnum").html(this.config.title || "叠加CAD文件");
            else
                $("#scnum").html(this.config.title || "叠加SHP文件");
        },
        _hide: function() {
            $('#' + this.containerId).css("display", "none");
        },
        /**
        *叠加CAD文件
        *@method addshp
        */
        addcad: function(fn, cx) {
            this._GetUploadObj("cad");
            $("#queding").off();
            $("#queding").bind('click', L.bind(function() {
                var url = this.cadUrlArray.join(';');
                if (url == null || !url) {
                    $('.zhuji').css('display', 'block');
                    return;
                }
                L.dci.app.util.showLoading();
                var tUrl = Project_ParamConfig.cadserver + "/Request/RequestServices.ashx";
                var layertypes = "Polyline;Annotation";
                var color = $("#custom").attr("value");
                var numb = $("#num").html();
                var params = {
                    "type": "cad",
                    "dwg": url,
                    "layerTypes": layertypes,
                    "lineWidth": numb,
                    "lineColor": color
                };
                this.addcad1(params, tUrl, fn, cx);
                this._hide();
            }, this));
        },

        //只返回要素
        addcad_3: function (fn, cx) {
            this._GetUploadObj("cad");
            $("#queding").off();
            $("#queding").bind('click', L.bind(function () {
                var url = this.cadUrlArray.join(';');
                if (url == null || !url) {
                    $('.zhuji').css('display', 'block');
                    return;
                }
                L.dci.app.util.showLoading();
                var tUrl = Project_ParamConfig.cadserver + "/Request/RequestServices.ashx";
                var layertypes = "Polyline;Annotation";
                var color = $("#custom").attr("value");
                var numb = $("#num").html();
                var params = {
                    "type": "cad",
                    "dwg": url,
                    "layerTypes": layertypes,
                    "lineWidth": numb,
                    "lineColor": color
                };
                this.addcad_2(params, tUrl, fn, cx);
                this._hide();
            }, this));
        },

        /**
        *上传错误处理函数
        *@method _fileQueueError
        *@param file {Object} SWFUpload文件对象
        *@param errorCode {Number} 错误代码
        *@param message {String} 错误信息
        *@private
        */
        _fileQueueError: function(file, errorCode, message) {
            try {
                if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
                    L.dci.app.util.dialog.alert("提示", "至多叠加" + this.settings.file_upload_limit + "个文件");
                    return;
                }
                var progress = new FileProgress(file, swfu.settings.custom_settings.progressTarget);

                progress.setShow(false);

                fg_fileSizes -= file.size;
                fg_erNum += 1;
                switch (errorCode) {
                case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                    MaxSizeError = true;
                    if (UploaFileMsg == "")
                        UploaFileMsg = file.name;
                    else
                        UploaFileMsg += "、" + file.name;
                    break;
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                    L.dci.app.util.dialog.alert(file.name + " 文件内容为空，不能上传0节字文件!");
                    this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                    L.dci.app.util.dialog.alert("不允许上传文件类型的文件");
                    this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                default:
                    if (file != null) {
                        progress.setStatus("Unhandled Error");
                    }
                    L.dci.app.util.dialog.alert("未知错误");
                    this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                }
            } catch (ex) {
                this.debug(ex);
            }
        },
        /**
        *随机生成CAD图层ID
        *@method randomCADGroupId
        *@return groupId{String} 图层ID
        *@private
        */
        randomCADGroupId: function() {
            var groupId = "cadLayer" + L.stamp({});
            return groupId;
        },
        /**
        *随机生成SHP图层ID
        *@method randomSHPGroupId
        *@return groupId{String} 图层ID
        *@private
        */
        randomSHPGroupId: function() {
            var groupId = "shpLayer" + L.stamp({});
            return groupId;
        },
        /**
        *ajax添加CAD方法
        *@method addcad1
        *@param params {Object} 添加CAD参数，eg.{"type": "cad","dwg": url, "layerTypes": layertypes,"lineWidth": numb,"lineColor": color};
        *@param tUrl {String}  请求地址
        *@private
        */
        addcad1: function(params, tUrl, fn, cx) {
            $.ajax({
              //跨域调用
                async: false,
                url: tUrl,
                data: params,
                type: "GET",
                dataType: 'jsonp',
                timeout: 5000,
                context: $.extend(this, params),
                success: function(json) {
                    var js1 = JSON.parse(json);
                    var map = L.DCI.App.pool.get('MultiMap').getActiveMap();
                    var index = 0;
                    for (var layer in js1) {
                        var color = this.lineColor;
                        var width = this.lineWidth;
                        var dwgPath = this.dwg;
                        var groupId = this.randomCADGroupId();
                        var name = this.cadFileNameArray[index];
                        var js2 = js1[layer];
                        var layers = [];
                        for (var attr in js2) {
                            switch (attr) {
                            case "Polyline":
                                $.each(js2[attr].features, L.bind(function(i, ft) {
                                    //用地平衡分析调用
                                    if (L.dci.app.pool.has("LandBalance") == true) {
                                        L.dci.app.pool.get("LandBalance").getCADRegion(ft);
                                    }

                                    //用地开发强度评价调用
                                    if (L.dci.app.pool.has("LandStrength") == true) {
                                        L.dci.app.pool.get("LandStrength").getCADRegion(ft);
                                    }
                                    var paths = ft.geometry.paths[0];
                                    var rs = [];
                                    $.each(paths, function(i0, ft0) {
                                        var relPoint = map.options.crs.projection.unproject(L.point([ft0[0], ft0[1]]));
                                        rs.push(relPoint);
                                    });
                                    var cadColor = "#"+this.aciToRgb(parseInt(ft.attributes["Color"]));
                                    var ply = L.polyline(rs).setStyle({ color: cadColor, weight: width });
                                    //var ply = L.polyline(rs).setStyle({ color: color, weight: width });
                                    ply.clone = function() {
                                        return L.polyline(this.getLatLngs(), this.options);
                                    };
                                    layers.push(ply);
                                    if (i == 0)
                                        map.map.fitBounds(ply.getBounds());

                                },this));
                                break;
                            case "Annotation":
                                break;
                            }
                        }

                        var options = {
                            id: 'layer-' + groupId,
                            declaredClass: "cad"
                        };
                        var lGroup = L.layerGroup(layers);
                        lGroup.options = options;
                        //克隆
                        lGroup.clone = function() {
                            var layers = this.getLayers();
                            var _layer = [];
                            $.each(layers, function(i, item) {
                                _layer.push(item.clone());
                            });
                            var lg = L.layerGroup(_layer);
                            lg.options = this.options;
                            return lg;
                        };
                        var objL = { groupId: groupId, group: lGroup, dwgPath: dwgPath, name: name };
                        var _map = L.dci.app.pool.get("map");
                        _map.cadLayerGroups.push(objL);

                        map.addCad(groupId);

                        var liename = '<li id=layer-dom-' + groupId + ' style="color:red" class="list-group-item"  title = ' + name + ' data-info="map-layer_l"><span class="icon-pitch-on list-group-item-img-display"></span><span>' + name + '</span></li>';
                        $("#cadul").append(liename);
                        index++;
                    }
                    this.initArray();
                    L.dci.app.util.hideLoading();
                    //叠加cad回调
                    if (typeof fn === 'function')
                        fn.apply(cx || this, [{ layers: layers, objL: objL, type: 'addcad' }]);
                },
                error: function(er) {
                    L.dci.app.util.hideLoading();
                    L.dci.app.util.dialog.error("错误提示", "调用CAD服务错误,请检查上传服务");
                }
            });
        },

        addcad_2: function (params, tUrl, fn, cx) {
            $.ajax({
                //跨域调用
                async: false,
                url: tUrl,
                data: params,
                type: "GET",
                dataType: 'jsonp',
                timeout: 5000,
                context: $.extend(this, params),
                success: function (json) {
                    var js1 = JSON.parse(json);
                    var map = L.DCI.App.pool.get('MultiMap').getActiveMap();
                    var layers_2 = [];
                    for (var layer in js1) {
                        var color = this.lineColor;
                        var width = this.lineWidth;
                        var js2 = js1[layer];
                        var layers = [];
                        for (var attr in js2) {
                            switch (attr) {
                                case "Polyline":
                                    $.each(js2[attr].features, L.bind(function (i, ft) {
                                        var paths = ft.geometry.paths[0];
                                        var rs = [];
                                        $.each(paths, function (i0, ft0) {
                                            var relPoint = map.options.crs.projection.unproject(L.point([ft0[0], ft0[1]]));
                                            rs.push(relPoint);
                                        });
                                        var cadColor = "#" + this.aciToRgb(parseInt(ft.attributes["Color"]));
                                        var ply = L.polyline(rs).setStyle({ color: cadColor, weight: width });
                                        ply.clone = function () {
                                            return L.polyline(this.getLatLngs(), this.options);
                                        };
                                        layers.push(ply);

                                    }, this));
                                    break;
                                case "Annotation":
                                    break;
                            }
                        }

                        layers_2.push(layers);
                    }
                    this.initArray();
                    L.dci.app.util.hideLoading();
                    //叠加cad回调
                    if (typeof fn === 'function')
                        fn.apply(cx || this, [{ layers: layers_2,type:'cad'}]);
                },
                error: function (er) {
                    L.dci.app.util.hideLoading();
                    L.dci.app.util.dialog.error("错误提示", "调用CAD服务错误,请检查上传服务");
                }
            });
        },
        /**
        *移除CAD要素
        *@method removerCAD
        */
        removerCAD: function() {
            var map = L.DCI.App.pool.get('MultiMap').getActiveMap();
            map.removeAllCad();
        },
        /**
        *ajax添加SHP方法
        *@method addshp1
        *@param params {Object} 添加SHP参数，eg.{"type": "cad","dwg": url, "layerTypes": layertypes,"lineWidth": numb,"lineColor": color};
        *@param tUrl {String}  请求地址
        *@private
        */
        addshp1: function(params, tUrl, fn, cx) {
            $.ajax({
              //跨域调用
                async: false,
                url: tUrl,
                data: params,
                type: "GET",
                dataType: 'jsonp',
                timeout: 5000,
                context: $.extend(this, params),
                success: function(json) {
                    var js1 = JSON.parse(json);
                    var map = L.DCI.App.pool.get('MultiMap').getActiveMap();
                    var index = 0;
                    isLanLng = Project_ParamConfig.crs.isLanLng ? true : false;
                    for (var layer in js1) //遍历shape集合
                    {
                        var color = this.lineColor ? this.lineColor : "#000000";
                        var width = this.lineWidth ? this.lineWidth : 1;
                        var shapePath = this.shapePath;
                        var groupId = this.randomSHPGroupId();
                        var name = this.shpNameArray[index];
                        var js2 = js1[layer]; //取出当前遍历到的一个shape
                        var layers = [];
                        $.each(js2.features, function(i, ft) { //遍历当前shp的每个feature  ft
                            switch (js2.geometryType) {
                            case "esriGeometryPolygon": //当前shp为面类型
                                {
                                    //用地平衡分析调用
                                    if (L.dci.app.pool.has("LandBalance") == true) {
                                        L.dci.app.pool.get("LandBalance").getSHPRegion(ft);
                                    }

                                    //用地开发强度评价调用
                                    if (L.dci.app.pool.has("LandStrength") == true) {
                                        L.dci.app.pool.get("LandStrength").getSHPRegion(ft);
                                    }

                                    var rings = ft.geometry.rings[0];
                                    var rs = [];
                                    $.each(rings, function(i0, ft0) { //取出面的每个点，进行坐标转换，将结果保存到rs数组中
                                        //@项目： 判断是地理坐标抑或是投影坐标
                                        if (isLanLng) {
                                            var relPoint = [ft0[1], ft0[0]];
                                        } else {
                                            var relPoint = map.options.crs.projection.unproject(L.point([ft0[0], ft0[1]]));
                                        }
                                        rs.push(relPoint);
                                    });
                                    var plygon = L.polygon(rs).setStyle({ color: color, weight: width,fill:false }); //创建一个新的面要素
                                    plygon.clone = function() {
                                        return L.polygon(this.getLatLngs(), this.options);
                                    };
                                    layers.push(plygon); //将面要素加载到图层集合中
                                    if (i == 0)
                                        map.map.fitBounds(plygon.getBounds());
                                }
                                break;
                            case "esriGeometryPolyline": //当前shp为线类型
                                {
                                    var paths = ft.geometry.paths[0];
                                    var rs = [];
                                    $.each(paths, function(i0, ft0) {

                                        //@项目： 判断是地理坐标抑或是投影坐标
                                        if (isLanLng) {
                                            var relPoint = [ft0[1], ft0[0]];
                                        } else {
                                            var relPoint = map.options.crs.projection.unproject(L.point([ft0[0], ft0[1]]));
                                        }

                                        rs.push(relPoint);
                                    });
                                    var ply = L.polyline(rs).setStyle({ color: color, weight: width });
                                    ply.clone = function() {
                                        return L.polyline(this.getLatLngs(), this.options);
                                    };
                                    layers.push(ply);
                                    if (i == 0)
                                        map.map.fitBounds(ply.getBounds());
                                }
                                break;
                            case "esriGeometryPoint": //当前shp为点类型
                                break;
                            }
                        });

                        var options = {
                            id: 'layer-' + groupId,
                            declaredClass: "shpfile"
                        };
                        var lGroup = L.layerGroup(layers);
                        lGroup.options = options;

                        lGroup.clone = function() {
                            var layers = this.getLayers();
                            var _layer = [];
                            $.each(layers, function(i, item) {
                                _layer.push(item.clone());
                            });

                            var lg = L.layerGroup(_layer);
                            lg.options = this.options;
                            return lg;
                        };
                        var objL = { groupId: groupId, group: lGroup, shapePath: shapePath, name: name };
                        var _map = L.dci.app.pool.get("map");
                        _map.shpLayerGroups.push(objL);
                        map.addShp(groupId);
                        var liename = '<li id=layer-dom-' + groupId + ' style="color:red" class="list-group-item"  title = ' + name + ' data-info="map-layer_l_s"><span class="icon-pitch-on list-group-item-img-display"></span><span>' + name + '</span></li>';
                        $("#cadul_s").append(liename);
                        index++;
                    } 
                    //叠加shp回调
                    if (typeof fn === 'function')
                        fn.apply(cx || this, [{ layers: layers, objL: objL, type: 'addshp' }]);
                    this.initArray();
                    L.dci.app.util.hideLoading();
                },
                error: function(er) {
                    L.dci.app.util.hideLoading();
                    L.dci.app.util.dialog.error("错误提示", "调用Shapfile服务错误,请检查上传服务");
                }
            });
        },

        addshp_2: function (params, tUrl, fn, cx) {
            $.ajax({
                //跨域调用
                async: false,
                url: tUrl,
                data: params,
                type: "GET",
                dataType: 'jsonp',
                timeout: 5000,
                context: $.extend(this, params),
                success: function (json) {
                    var js1 = JSON.parse(json);
                    var map = L.DCI.App.pool.get('MultiMap').getActiveMap();
                    var isLanLng = Project_ParamConfig.crs.isLanLng ? true : false;
                    var layers_2 = [];
                    for (var layer in js1) //遍历shape集合
                    {
                        var color = this.lineColor ? this.lineColor : "#000000";
                        var width = this.lineWidth ? this.lineWidth : 1;
                        var js2 = js1[layer]; //取出当前遍历到的一个shape
                        var layers = [];
                        $.each(js2.features, function (i, ft) { //遍历当前shp的每个feature  ft
                            switch (js2.geometryType) {
                                case "esriGeometryPolygon": //当前shp为面类型
                                    {
                                        var rings = ft.geometry.rings[0];
                                        var rs = [];
                                        $.each(rings, function (i0, ft0) {
                                            //取出面的每个点，进行坐标转换，将结果保存到rs数组中
                                            //@项目： 判断是地理坐标抑或是投影坐标
                                            if (isLanLng) {
                                                var relPoint = [ft0[1], ft0[0]];
                                            } else {
                                                var relPoint = map.options.crs.projection.unproject(L.point([ft0[0], ft0[1]]));
                                            }
                                            rs.push(relPoint);
                                        });
                                        var plygon = L.polygon(rs).setStyle({ color: color, weight: width }); //创建一个新的面要素
                                        plygon.clone = function () {
                                            return L.polygon(this.getLatLngs(), this.options);
                                        };
                                        layers.push(plygon);
                                    }
                                    break;
                                case "esriGeometryPolyline": //当前shp为线类型
                                    {
                                        var paths = ft.geometry.paths[0];
                                        var rs = [];
                                        $.each(paths, function (i0, ft0) {

                                            //@项目： 判断是地理坐标抑或是投影坐标
                                            if (isLanLng) {
                                                var relPoint = [ft0[1], ft0[0]];
                                            } else {
                                                var relPoint = map.options.crs.projection.unproject(L.point([ft0[0], ft0[1]]));
                                            }

                                            rs.push(relPoint);
                                        });
                                        var ply = L.polyline(rs).setStyle({ color: color, weight: width });
                                        ply.clone = function () {
                                            return L.polyline(this.getLatLngs(), this.options);
                                        };
                                        layers.push(ply);
                                    }
                                    break;
                                case "esriGeometryPoint": //当前shp为点类型
                                    break;
                            }

                            layers_2.push(layers);
                        });

                    }

                    this.initArray();
                    L.dci.app.util.hideLoading();

                    //叠加shp回调
                    if (typeof fn === 'function')
                        fn.apply(cx || this, [{ layers: layers_2,type:'shp' }]);
                },
                error: function (er) {
                    L.dci.app.util.hideLoading();
                    L.dci.app.util.dialog.error("错误提示", "调用Shapfile服务错误,请检查上传服务");
                }
            });
        },
        /**
        *上传CAD成功函数
        *@method uploadCADSuccess
        *@param file {Object} SWFUpload文件对象
        *@param serverData {String}  
        *@private
        */
        uploadCADSuccess: function(file, serverData) {
            $("#divprogresscontainer").attr("class", "divprogress1");
            var length = $("#" + this.containerId).find('.progressobj').length - 1;

            try {
                var _this = this.settings.custom_settings._this;
                var progress = new FileProgress(file, swfu.settings.custom_settings.progressTarget);
                progress.setComplete(this.settings);
                fg_uploads += file.size;
                _this.cadUrlArray.push(serverData);
                _this.cadFileNameArray.push(file.name);
                if (_this.cadUrlArray == null || _this.cadUrlArray.length == 0) {
                    L.dci.app.util.dialog.alert("提示", "上传没有成功,请重新上传");
                    return;
                }
                var inde = file.index + 1;
                if (length != inde) {
                    $("#scnum").html("正在上传文件" + inde);
                } else {
                    $("#scnum").html("文件上传完成");
                }
            } catch (ex) {
                L.dci.app.util.hideLoading();
                this.debug(ex);
            }

        },
        /**
        *上传SHP成功函数
        *@method randomSHPGroupId
        *@param file {Object} SWFUpload文件对象
        *@param serverData {String}  
        *@private
        */
        uploadSHPSuccess: function (file, serverData) {
            var _this = this.settings.custom_settings._this;
            $("#divprogresscontainer").attr("class", "divprogress1");
            var length = $("#" + _this.containerId).find('.progressobj').length - 1;
            try {              
                var progress = new FileProgress(file, swfu.settings.custom_settings.progressTarget);
                progress.setComplete(this.settings);
                fg_uploads += file.size;
                if (file.type.toLowerCase() == '.shp') {
                    _this.shpNameArray.push(file.name);
                    _this.shpUrlArray.push(serverData);
                }
                var inde = file.index + 1;
                if (length != inde) {
                    $("#scnum").html("正在上传文件" + inde);
                } else {
                    $("#scnum").html("文件上传完成");
                }
            } catch (ex) {
                L.dci.app.util.hideLoading();
                this.debug(ex);
            }
        },
        uploadSHPSuccess2: function (file, serverData) {
            var _this = this.settings.custom_settings._this;
            $("#divprogresscontainer").attr("class", "divprogress1");
            var length = $("#" + _this.containerId).find('.progressobj').length - 1;
            try {
                var progress = new FileProgress(file, swfu.settings.custom_settings.progressTarget);
                progress.setComplete(this.settings);
                fg_uploads += file.size;
                if (file.type.toLowerCase() == '.shp') {
                    _this.shpNameArray.push(file.name);
                    _this.shpUrlArray.push(serverData);
                } else {
                    _this.cadFileNameArray.push(file.name);
                    _this.cadUrlArray.push(serverData);                  
                }
                var inde = file.index + 1;
                if (length != inde) {
                    $("#scnum").html("正在上传文件" + inde);
                } else {
                    $("#scnum").html("文件上传完成");
                }
            } catch (ex) {
                L.dci.app.util.hideLoading();
                this.debug(ex);
            }
        },
        /**
        *转换cad颜色序号为rgb函数
        *@method aciToRgb
        *@param aci {String}  
        *@private
        */
        aciToRgb:function(aci){switch(aci){case 0:return rgbToHex("0,0,0");case 1:return rgbToHex("255,0,0");case 2:return rgbToHex("255,255,0");case 3:return rgbToHex("0,255,0");case 4:return rgbToHex("0,255,255");case 5:return rgbToHex("0,0,255");case 6:return rgbToHex("255,0,255");case 7:return rgbToHex("255,255,255");case 8:return rgbToHex("128,128,128");case 9:return rgbToHex("192,192,192");case 10:return rgbToHex("255,0,0");case 11:return rgbToHex("255,127,127");case 12:return rgbToHex("204,0,0");case 13:return rgbToHex("204,102,102");case 14:return rgbToHex("153,0,0");case 15:return rgbToHex("153,76,76");case 16:return rgbToHex("127,0,0");case 17:return rgbToHex("127,63,63");case 18:return rgbToHex("76,0,0");case 19:return rgbToHex("76,38,38");case 20:return rgbToHex("255,63,0");case 21:return rgbToHex("255,159,127");case 22:return rgbToHex("204,51,0");case 23:return rgbToHex("204,127,102");case 24:return rgbToHex("153,38,0");case 25:return rgbToHex("153,95,76");case 26:return rgbToHex("127,31,0");case 27:return rgbToHex("127,79,63");case 28:return rgbToHex("76,19,0");case 29:return rgbToHex("76,47,38");case 30:return rgbToHex("255,127,0");case 31:return rgbToHex("255,191,127");case 32:return rgbToHex("204,102,0");case 33:return rgbToHex("204,153,102");case 34:return rgbToHex("153,76,0");case 35:return rgbToHex("153,114,76");case 36:return rgbToHex("127,63,0");case 37:return rgbToHex("127,95,63");case 38:return rgbToHex("76,38,0");case 39:return rgbToHex("76,57,38");case 40:return rgbToHex("255,191,0");case 41:return rgbToHex("255,223,127");case 42:return rgbToHex("204,153,0");case 43:return rgbToHex("204,178,102");case 44:return rgbToHex("153,114,0");case 45:return rgbToHex("153,133,76");case 46:return rgbToHex("127,95,0");case 47:return rgbToHex("127,111,63");case 48:return rgbToHex("76,57,0");case 49:return rgbToHex("76,66,38");case 50:return rgbToHex("255,255,0");case 51:return rgbToHex("255,255,127");case 52:return rgbToHex("204,204,0");case 53:return rgbToHex("204,204,102");case 54:return rgbToHex("153,153,0");case 55:return rgbToHex("153,153,76");case 56:return rgbToHex("127,127,0");case 57:return rgbToHex("127,127,63");case 58:return rgbToHex("76,76,0");case 59:return rgbToHex("76,76,38");case 60:return rgbToHex("191,255,0");case 61:return rgbToHex("223,255,127");case 62:return rgbToHex("153,204,0");case 63:return rgbToHex("178,204,102");case 64:return rgbToHex("114,153,0");case 65:return rgbToHex("133,153,76");case 66:return rgbToHex("95,127,0");case 67:return rgbToHex("111,127,63");case 68:return rgbToHex("57,76,0");case 69:return rgbToHex("66,76,38");case 70:return rgbToHex("127,255,0");case 71:return rgbToHex("191,255,127");case 72:return rgbToHex("102,204,0");case 73:return rgbToHex("153,204,102");case 74:return rgbToHex("76,153,0");case 75:return rgbToHex("114,153,76");case 76:return rgbToHex("63,127,0");case 77:return rgbToHex("95,127,63");case 78:return rgbToHex("38,76,0");case 79:return rgbToHex("57,76,38");case 80:return rgbToHex("63,255,0");case 81:return rgbToHex("159,255,127");case 82:return rgbToHex("51,204,0");case 83:return rgbToHex("127,204,102");case 84:return rgbToHex("38,153,0");case 85:return rgbToHex("95,153,76");case 86:return rgbToHex("31,127,0");case 87:return rgbToHex("79,127,63");case 88:return rgbToHex("19,76,0");case 89:return rgbToHex("47,76,38");case 90:return rgbToHex("0,255,0");case 91:return rgbToHex("127,255,127");case 92:return rgbToHex("0,204,0");case 93:return rgbToHex("102,204,102");case 94:return rgbToHex("0,153,0");case 95:return rgbToHex("76,153,76");case 96:return rgbToHex("0,127,0");case 97:return rgbToHex("63,127,63");case 98:return rgbToHex("0,76,0");case 99:return rgbToHex("38,76,38");case 100:return rgbToHex("0,255,63");case 101:return rgbToHex("127,255,159");case 102:return rgbToHex("0,204,51");case 103:return rgbToHex("102,204,127");case 104:return rgbToHex("0,153,38");case 105:return rgbToHex("76,153,95");case 106:return rgbToHex("0,127,31");case 107:return rgbToHex("63,127,79");case 108:return rgbToHex("0,76,19");case 109:return rgbToHex("38,76,47");case 110:return rgbToHex("0,255,127");case 111:return rgbToHex("127,255,191");case 112:return rgbToHex("0,204,102");case 113:return rgbToHex("102,204,153");case 114:return rgbToHex("0,153,76");case 115:return rgbToHex("76,153,114");case 116:return rgbToHex("0,127,63");case 117:return rgbToHex("63,127,95");case 118:return rgbToHex("0,76,38");case 119:return rgbToHex("38,76,57");case 120:return rgbToHex("0,255,191");case 121:return rgbToHex("127,255,223");case 122:return rgbToHex("0,204,153");case 123:return rgbToHex("102,204,178");case 124:return rgbToHex("0,153,114");case 125:return rgbToHex("76,153,133");case 126:return rgbToHex("0,127,95");case 127:return rgbToHex("63,127,111");case 128:return rgbToHex("0,76,57");case 129:return rgbToHex("38,76,66");case 130:return rgbToHex("0,255,255");case 131:return rgbToHex("127,255,255");case 132:return rgbToHex("0,204,204");case 133:return rgbToHex("102,204,204");case 134:return rgbToHex("0,153,153");case 135:return rgbToHex("76,153,153");case 136:return rgbToHex("0,127,127");case 137:return rgbToHex("63,127,127");case 138:return rgbToHex("0,76,76");case 139:return rgbToHex("38,76,76");case 140:return rgbToHex("0,191,255");case 141:return rgbToHex("127,223,255");case 142:return rgbToHex("0,153,204");case 143:return rgbToHex("102,178,204");case 144:return rgbToHex("0,114,153");case 145:return rgbToHex("76,133,153");case 146:return rgbToHex("0,95,127");case 147:return rgbToHex("63,111,127");case 148:return rgbToHex("0,57,76");case 149:return rgbToHex("38,66,76");case 150:return rgbToHex("0,127,255");case 151:return rgbToHex("127,191,255");case 152:return rgbToHex("0,102,204");case 153:return rgbToHex("102,153,204");case 154:return rgbToHex("0,76,153");case 155:return rgbToHex("76,114,153");case 156:return rgbToHex("0,63,127");case 157:return rgbToHex("63,95,127");case 158:return rgbToHex("0,38,76");case 159:return rgbToHex("38,57,76");case 160:return rgbToHex("0,63,255");case 161:return rgbToHex("127,159,255");case 162:return rgbToHex("0,51,204");case 163:return rgbToHex("102,127,204");case 164:return rgbToHex("0,38,153");case 165:return rgbToHex("76,95,153");case 166:return rgbToHex("0,31,127");case 167:return rgbToHex("63,79,127");case 168:return rgbToHex("0,19,76");case 169:return rgbToHex("38,47,76");case 170:return rgbToHex("0,0,255");case 171:return rgbToHex("127,127,255");case 172:return rgbToHex("0,0,204");case 173:return rgbToHex("102,102,204");case 174:return rgbToHex("0,0,153");case 175:return rgbToHex("76,76,153");case 176:return rgbToHex("0,0,127");case 177:return rgbToHex("63,63,127");case 178:return rgbToHex("0,0,76");case 179:return rgbToHex("38,38,76");case 180:return rgbToHex("63,0,255");case 181:return rgbToHex("159,127,255");case 182:return rgbToHex("51,0,204");case 183:return rgbToHex("127,102,204");case 184:return rgbToHex("38,0,153");case 185:return rgbToHex("95,76,153");case 186:return rgbToHex("31,0,127");case 187:return rgbToHex("79,63,127");case 188:return rgbToHex("19,0,76");case 189:return rgbToHex("47,38,76");case 190:return rgbToHex("127,0,255");case 191:return rgbToHex("191,127,255");case 192:return rgbToHex("102,0,204");case 193:return rgbToHex("153,102,204");case 194:return rgbToHex("76,0,153");case 195:return rgbToHex("114,76,153");case 196:return rgbToHex("63,0,127");case 197:return rgbToHex("95,63,127");case 198:return rgbToHex("38,0,76");case 199:return rgbToHex("57,38,76");case 200:return rgbToHex("191,0,255");case 201:return rgbToHex("223,127,255");case 202:return rgbToHex("153,0,204");case 203:return rgbToHex("178,102,204");case 204:return rgbToHex("114,0,153");case 205:return rgbToHex("133,76,153");case 206:return rgbToHex("95,0,127");case 207:return rgbToHex("111,63,127");case 208:return rgbToHex("57,0,76");case 209:return rgbToHex("66,38,76");case 210:return rgbToHex("255,0,255");case 211:return rgbToHex("255,127,255");case 212:return rgbToHex("204,0,204");case 213:return rgbToHex("204,102,204");case 214:return rgbToHex("153,0,153");case 215:return rgbToHex("153,76,153");case 216:return rgbToHex("127,0,127");case 217:return rgbToHex("127,63,127");case 218:return rgbToHex("76,0,76");case 219:return rgbToHex("76,38,76");case 220:return rgbToHex("255,0,191");case 221:return rgbToHex("255,127,223");case 222:return rgbToHex("204,0,153");case 223:return rgbToHex("204,102,178");case 224:return rgbToHex("153,0,114");case 225:return rgbToHex("153,76,133");case 226:return rgbToHex("127,0,95");case 227:return rgbToHex("127,63,111");case 228:return rgbToHex("76,0,57");case 229:return rgbToHex("76,38,66");case 230:return rgbToHex("255,0,127");case 231:return rgbToHex("255,127,191");case 232:return rgbToHex("204,0,102");case 233:return rgbToHex("204,102,153");case 234:return rgbToHex("153,0,76");case 235:return rgbToHex("153,76,114");case 236:return rgbToHex("127,0,63");case 237:return rgbToHex("127,63,95");case 238:return rgbToHex("76,0,38");case 239:return rgbToHex("76,38,57");case 240:return rgbToHex("255,0,63");case 241:return rgbToHex("255,127,159");case 242:return rgbToHex("204,0,51");case 243:return rgbToHex("204,102,127");case 244:return rgbToHex("153,0,38");case 245:return rgbToHex("153,76,95");case 246:return rgbToHex("127,0,31");case 247:return rgbToHex("127,63,79");case 248:return rgbToHex("76,0,19");case 249:return rgbToHex("76,38,47");case 250:return rgbToHex("51,51,51");case 251:return rgbToHex("91,91,91");case 252:return rgbToHex("132,132,132");case 253:return rgbToHex("173,173,173");case 254:return rgbToHex("214,214,214");case 255:return rgbToHex("255,255,255");default:return rgbToHex("0,0,0");}function rgbToHex(rgb){var r=parseInt(rgb.split(",")[0]);var g=parseInt(rgb.split(",")[1]);var b=parseInt(rgb.split(",")[2]);return((r << 16) | (g << 8) | b).toString(16);}}
    });
    return L.DCI.AddCad;
});